﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Xml;
using YJKRevitDictionary.Operation;

namespace YJKRevitDimensionText.Forms
{
	public partial class DlgEditDirectory : System.Windows.Forms.Form
	{
		public DlgEditDirectory(DlgDictForm mForm)
		{
			this.mainForm = mForm;
			this.InitializeComponent();
			if (this.mainForm.treeView1.SelectedNode != null)
			{
				this.tbxName.Text = this.mainForm.treeView1.SelectedNode.Text;
			}
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			if (this.mainForm.treeView1.SelectedNode != null)
			{
				if (DictOperation.EditDirectory((XmlNode)this.mainForm.treeView1.SelectedNode.Tag, this.tbxName.Text, this.mainForm.dictFile.FullName))
				{
					new DictOperation(this.mainForm.dictFile.FullName).FillTree(this.mainForm.treeView1);
					this.mainForm.lbxEntry.Items.Clear();
					XmlNode node = (XmlNode)this.mainForm.treeView1.Nodes[0].Tag;
					this.mainForm.GetChildAttributes(node, this.mainForm.lbxEntry);
					this.mainForm.lbxEntry.Sorted = true;
					this.mainForm.textBox1.Text = "";
					MessageBox.Show("修改成功", "盈建科词库");
				}
				else
				{
					MessageBox.Show("修改失败", "盈建科词库");
				}
			}
			base.Close();
		}

		public static DlgEditDirectory GetInstance(DlgDictForm main)
		{
			if (DlgEditDirectory.ded == null || DlgEditDirectory.ded.IsDisposed)
			{
				DlgEditDirectory.ded = new DlgEditDirectory(main);
				DlgEditDirectory.ded.MdiParent = main.ActiveMdiChild;
			}
			return DlgEditDirectory.ded;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private DlgDictForm mainForm;

		private static DlgEditDirectory ded;
	}
}
